package com.ceair.flight.refund.util;

import com.ceair.flight.refund.location.dt.enums.RefundStatus;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.TypeHandler;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class EnumOrdinalTypeHandler implements TypeHandler<String> {

    @Override
    public void setParameter(PreparedStatement ps, int i,
            String parameter, JdbcType jdbcType) throws SQLException {

    }

    @Override
    public String getResult(ResultSet rs, String columnName)
            throws SQLException {
        RefundStatus valueOf = RefundStatus.getByCode(rs.getString(columnName));
        if (valueOf == null) {
            return "Unknow";
        }
        return valueOf.getDescription();
    }

    @Override
    public String getResult(ResultSet rs, int columnIndex) throws SQLException {
        return null;
    }

    @Override
    public String getResult(CallableStatement cs, int columnIndex)
            throws SQLException {
        return null;
    }

}
